{extend name='view/common/_container'}
{block name="content"}
<div class="ibox float-e-margins">
<input type="hidden" name="id" id="id" value="{$info.id}">
{if condition="$info.id eq ''"}
<input type="hidden" name="menu_id" id="menu_id" value="{$menu_id}">
{/if}
	<div class="ibox-content">
		<div class="form-horizontal" id="CodeInfoForm">
			<div class="row" style="margin-top:-20px;">
				<div class="layui-tab layui-tab-brief" lay-filter="test">
					<ul class="layui-tab-title">
						<li class="layui-this">基本信息</li>
						<li>拓展信息</li>
						<li>多表操作配置</li>
					</ul>
					
					<div class="layui-tab-content" style="margin-top:10px;">
						<div class="layui-tab-item layui-show">
							<div class="col-sm-9">
							<!-- form start -->
								<div class="form-group">
									<label class="col-sm-2 control-label">操作名：</label>
									<div class="col-sm-9">
										<input type="text" id="name" value="{$info.name}" name="name" class="form-control" placeholder="请输入操作名">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">方法名称：</label>
									<div class="col-sm-9">
										<input type="text" id="action_name" value="{$info.action_name}" name="action_name" class="form-control" placeholder="请输入方法名称">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">方法类型：</label>
									<div class="col-sm-9">
										<select lay-ignore name="type" class="form-control" id="type">
											<option value="">请选择</option>
											{foreach name="actionList" id="vo"}
											<option value="{$key}" {if condition="$info.type eq $key"}selected{/if}>{$vo}</option>
											{/foreach}
										</select>
									</div>
								</div>
								<div class="form-group layui-form">
									<label class="col-sm-2 control-label">操作字段：</label>
									<div class="col-sm-9">
										<?php $menu_id = isset($info['menu_id']) ? $info['menu_id'] : request()->param('menu_id');?>
										{query table="field" sqlstr="menu_id=$menu_id and is_post = 1" order="sortid asc"}
										<input value="{$query.field}" data-type="{$query.type}" name="fields" lay-filter="hope" class="checkbox" type="checkbox" {if in_array($query['field'],explode(',',$info['fields']))}checked{/if} title="{$query.name}">
										{/query}
									</div>
								</div>
								
								<div class="form-group layui-form">
									<label class="col-sm-2 control-label">按钮是否显示列表：</label>
									<div class="col-sm-9">
										<input name="button_status" value="1" type="radio" {if condition="$info.button_status eq 1"}checked{/if} title="是">
										<input name="button_status" value="0" type="radio" {if condition="$info.button_status eq 0"}checked{/if} title="否">
									</div>
								</div>
								
								<div class="form-group layui-form">
									<label class="col-sm-2 control-label">按钮背景色：</label>
									<div class="col-sm-9">
										<select lay-ignore name="lable_color" class="form-control" id="lable_color">
											<option value="primary" style="background-color:#1DB394" {if condition="$info.lable_color eq 'primary'"}selected{/if}>primary</option>
											<option value="success" style="background-color:#1E84C6" {if condition="$info.lable_color eq 'success'"}selected{/if}>success</option>
											<option value="info" style="background-color:#25C6C8" {if condition="$info.lable_color eq 'info'"}selected{/if}>info</option>
											<option value="warning" style="background-color:#F8AC5A" {if condition="$info.lable_color eq 'warning'"}selected{/if}>warning</option>
											<option value="danger" style="background-color:#D7524B" {if condition="$info.lable_color eq 'danger'"}selected{/if}>danger</option>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">配置信息：</label>
									<div class="col-sm-9">
										<input type="text" id="remark" value="{$info.remark}" name="remark" class="form-control" placeholder="请输入默认值">
										<span class="help-block m-b-none">弹窗大小或者修改值配置</span>
									</div>
								</div>
								
							<!-- form end -->
							</div>
						</div>
						
						<div class="layui-tab-item">
							<div class="col-sm-7">
							<div class="form-group layui-form">
								<label class="col-sm-2 control-label">控制器方法是否生成：</label>
								<div class="col-sm-9">
									<?php if(!isset($info['is_controller_create'])){ $info['is_controller_create'] = 1; }; ?>
									<input name="is_controller_create" value="1" type="radio" {if condition="$info.is_controller_create eq 1"}checked{/if} title="是">
									<input name="is_controller_create" value="0" type="radio" {if condition="$info.is_controller_create eq 0"}checked{/if} title="否">
								</div>
							</div>
							<div class="form-group layui-form">
								<label class="col-sm-2 control-label">服务层方法是否生成：</label>
								<div class="col-sm-9">
									<?php if(!isset($info['is_service_create'])){ $info['is_service_create'] = 1; }; ?>
									<input name="is_service_create" value="1" type="radio" {if condition="$info.is_service_create eq 1"}checked{/if} title="是">
									<input name="is_service_create" value="0" type="radio" {if condition="$info.is_service_create eq 0"}checked{/if} title="否">
								</div>
							</div>
							<div class="form-group layui-form">
								<label class="col-sm-2 control-label">视图是否生成：</label>
								<div class="col-sm-9">
									<?php if(!isset($info['is_view_create'])){ $info['is_view_create'] = 1; }; ?>
									<input name="is_view_create" value="1" type="radio" {if condition="$info.is_view_create eq 1"}checked{/if} title="是">
									<input name="is_view_create" value="0" type="radio" {if condition="$info.is_view_create eq 0"}checked{/if} title="否">
								</div>
							</div>
							<div class="form-group layui-form">
								<label class="col-sm-2 control-label">方法按钮显示状态：</label>
								<div class="col-sm-9">
									<?php if(!isset($info['is_view'])){ $info['is_view'] = 1; }; ?>
									<input name="is_view" value="1" type="radio" {if condition="$info.is_view eq 1"}checked{/if} title="是">
									<input name="is_view" value="0" type="radio" {if condition="$info.is_view eq 0"}checked{/if} title="否">
								</div>
							</div>
							<div class="form-group layui-form">
									<label class="col-sm-2 control-label">列表选中方式：</label>
									<div class="col-sm-9">
										<?php if(!isset($info['select_type'])){ $info['select_type'] = 2; }; ?>
										<input name="select_type" value="1" type="radio" {if condition="$info.select_type eq 1"}checked{/if} title="单选">
										<input name="select_type" value="2" type="radio" {if condition="$info.select_type eq 2"}checked{/if} title="多选">
									</div>
								</div>
							<div class="form-group layui-form">
								<label class="col-sm-2 control-label">每页显示数据：</label>
								<div class="col-sm-9">					
									<input type="text" id="pagesize" name="pagesize" value="{$info.pagesize}" class="form-control" placeholder="每页显示多少条数据，默认20">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">默认排序：</label>
								<div class="col-sm-9">					
									<input type="text" id="default_orderby" name="default_orderby" value="{$info.default_orderby}"  class="form-control" placeholder="默认排序，如不填则按照主键倒序">
								</div>
							</div>
							
							<div class="form-group layui-form">
								<label class="col-sm-2 control-label">配置树级列表：</label>
								<div class="col-sm-9">					
									<input type="text" id="tree_config" name="tree_config" value="{$info.tree_config}" class="form-control" placeholder="当前父级ID,显示字段 例如 pid,title">
									<span class="help-block m-b-none">生成树级列表 格式父ID,显示字段名称 例如pid,title</span>
								</div>
							</div>
							
							<div class="form-group layui-form">
								<label class="col-sm-2 control-label">按钮icon图标：</label>
								<div class="col-sm-9">
									<input type="text" id="bs_icon" name="bs_icon" value="{$info.bs_icon}" class="form-control" placeholder="请输入图标名称">
									<span class="help-block m-b-none"><a  target="_blank" style="color:#ff0000" onclick="CodeInfoDlg.icon('bs_icon')">点击查看图标列表 </a></span>
								</div>
							</div>
							<div class="form-group layui-form">
								<label class="col-sm-2 control-label">方法描述：</label>
								<div class="col-sm-9">
									<textarea id="block_name" name="block_name" class="form-control" placeholder="请输入方法">{$info.block_name}</textarea>
								</div>
							</div>
							<div class="form-group layui-form">
								<label class="col-sm-2 control-label">按钮跳转地址：</label>
								<div class="col-sm-9">
									<input type="text" id="jump" name="jump" value="{$info.jump}"  class="form-control" placeholder="请输入跳转地址">
								</div>
							</div>
						</div>
						</div>
						
						<div class="layui-tab-item">
							<div class="col-sm-9">
								<div class="form-group">
									<label class="col-sm-2 control-label">关联表：</label>
									<div class="col-sm-9">
										<?php if(!isset($info['relate_table'])){ $info['relate_table'] = ''; }; ?>
										<select lay-ignore name="relate_table" class="form-control chosen" data-placeholder='请选择所属分类'  id="relate_table">
										<option value="">请选择关联表</option>
											{volist name="tableList" id="vo"}
												<option value="{$vo}" {if condition="$info.relate_table eq $vo"}selected{/if}>{$vo}</option>
											{/volist}
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">关联字段：</label>
									<div class="col-sm-9">
										<input type="text" id="relate_field" value="{$info.relate_field}" name="relate_field" class="form-control" placeholder="请输入关联表 如果不是关联查询请勿填写">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">查询字段字段：</label>
									<div class="col-sm-9">
										<input type="text" id="list_field" value="{$info.list_field}" name="list_field" class="form-control" placeholder="请输入关联表需要查询的字段">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">sql数据源：</label>
									<div class="col-sm-9">
										<textarea id="sql_query" name="sql_query" class="form-control" placeholder="sql查询语句 前面的关联查询取消">{$info.sql_query}</textarea>
									</div>
								</div>
								
							</div>
						</div>
						
						
					</div>
					
				</div>
			</div>
			<div class="row btn-group-m-t">
				<div class="col-sm-10 col-sm-offset-1">
					<button type="button" class="btn btn-primary" onclick="{if condition="$info.id neq ''"}CodeInfoDlg.update(){else/}CodeInfoDlg.add(){/if}" id="ensure">
						<i class="fa fa-check"></i>&nbsp;确认提交
					</button>
					<button type="button" class="btn btn-danger" onclick="CodeInfoDlg.close()" id="cancel">
						<i class="fa fa-eraser"></i>&nbsp;取消
					</button>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<link href='__PUBLIC__/static/js/plugins/chosen/chosen.min.css' rel='stylesheet'/>
<script src='__PUBLIC__/static/js/plugins/chosen/chosen.jquery.js'></script>
<script>

$(function(){$('.chosen').chosen({})})

layui.use(['form'], function () {
	form = layui.form;
	form.on('checkbox(hope)',function(data){
		var type = $("#type").val();
		var data_type = $(this).attr('data-type');
		if(type !== '1'){
			var len=$(".checkbox:checked").length;
			var width,height,size;
			
			if(len<=3){
				if(data_type == 8 || data_type == 9){
					width = 800;
				}else{
					width = 600;
				}				
				height = len*50+300;
				size = width+'px|'+height+"px";
			}else if(len>3 && len<=8){
				width = 800;
				height = len*50+200;
				size = width+'px|'+height+"px";
			}else if(len>8){
				width = 800;
				size = width+'px|100%';
			}
			
			
			$("#remark").val(size);	
		}
	});
});

layui.use('element', function(){
	var element = layui.element;
	element.on('tab(test)', function(elem){
		$(".chosen-container").css('width','100%');
	});
});


$(function(){
	$("#type").change(function(){
		var type = $(this).val().toString();
		switch(type){
			case '3':
				$("#bs_icon").val('fa fa-plus');
				$("#block_name").val('创建数据');
			break;
			
			case '4':
				$("#bs_icon").val('fa fa-edit');
				$("#block_name").val('编辑数据');
			break;
			
			case '14':
				$("#bs_icon").val('fa fa-edit');
				$("#block_name").val('批量编辑数据');
			break;
			
			case '5':
				$("#bs_icon").val('fa fa-trash');
				$("#block_name").val('删除数据');
			break;
			
			case '6':
				$("#bs_icon").val('fa fa-pencil');
				$("#block_name").val('修改状态');
				$("#remark").val('');
			break;
			
			case '7':
				$("#bs_icon").val('fa fa-edit');
				$("#block_name").val('数值加');
				$("#remark").val('600px|300px');
			break;
			
			case '8':
				$("#bs_icon").val('fa fa-edit');
				$("#block_name").val('数值减');
				$("#remark").val('600px|300px');
			break;
			
			case '9':
				$("#bs_icon").val('fa fa-lock');
				$("#block_name").val('修改密码');
				$("#remark").val('600px|300px');
			break;
			
			case '10':
				$("#bs_icon").val('fa fa-plus');
				$("#block_name").val('跳转链接');
			break;
			
			case '11':
				$("#bs_icon").val('fa fa-plus');
				$("#block_name").val('弹窗连接');
				$("#remark").val('90%|90%');
			break;
			
			case '12':
				$("#bs_icon").val('fa fa-download');
				$("#block_name").val('数据导出');
			break;
			
			case '13':
				$("#bs_icon").val('fa fa-upload');
				$("#block_name").val('数据导入');
				$("#remark").val('800px|300px');
			break;
			
			case '16':
				$("input[type=radio][name=is_view][value=0]").attr("checked",'checked');
				$("#block_name").val('修改排序\开关按钮操作');
				layui.use(['form'], function () {
					form = layui.form();
					form.render();
				});
			break;
		}
	});
	
})

var CodeInfoDlg = {
	CodeInfoData: {},
	deptZtree: null,
	pNameZtree: null,
	validateFields: {
		name: {
			validators: {
				notEmpty: {
					message: '操作名不能为空'
	 			}
	 		}
	 	},
		action_name: {
			validators: {
				notEmpty: {
					message: '方法不能为空'
	 			},
				regexp: {
					regexp: /^[a-zA-Z_]+$/,
					message: '大小写字母组合'
	 			},
	 		}
	 	},
		type: {
			validators: {
				notEmpty: {
					message: '方法类型不能为空'
	 			}
	 		}
	 	},
		pagesize: {
			validators: {
				regexp: {
					regexp: /^[0-9]*$/,
					message: '请输入整数'
	 			}
	 		}
	 	},
		
	 }
}


CodeInfoDlg.clearData = function () {
	 this.CodeInfoData = {};
};


CodeInfoDlg.set = function (key, val) {
	 this.CodeInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
	 return this;
};


CodeInfoDlg.get = function (key) {
	 return $("#" + key).val();
};


CodeInfoDlg.close = function () {
	 var index = parent.layer.getFrameIndex(window.name);
	 parent.layer.close(index);
};


CodeInfoDlg.collectData = function () {
	this.set('id').set('menu_id').set('name').set('action_name').set('type').set('block_name').set('remark').set('sortid').set('lable_color').set('bs_icon').set('relate_table').set('relate_field').set('list_field').set('orderby').set('sql_query').set('default_orderby').set('pagesize').set('jump').set('tree_config').set('cache_time').set('request_type').set('do_condition');
};

CodeInfoDlg.icon = function () {
	var index = layer.open({type: 2,title: '设置图标',area: ['800px', '500px'],fix: false, maxmin: true,content: Feng.ctxPath + '/Base/icon/field/bs_icon'});
		this.layerIndex = index;
}


CodeInfoDlg.config = function () {
	var index = layer.open({type: 2,title: '操作配置说明',area: ['100%', '500px'],fix: false, maxmin: true,content: Feng.ctxPath + '/Sys.Action/config'});
		this.layerIndex = index;
}



CodeInfoDlg.add = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }

	 var is_controller_create = $("input[name = 'is_controller_create']:checked").val();
	 var is_service_create = $("input[name = 'is_service_create']:checked").val();
	 var is_view_create = $("input[name = 'is_view_create']:checked").val();
	 var is_view = $("input[name = 'is_view']:checked").val();
	 var log_status = $("input[name = 'log_status']:checked").val();
	 var api_auth = $("input[name = 'api_auth']:checked").val();
	 var sms_auth = $("input[name = 'sms_auth']:checked").val();
	 var captcha_auth = $("input[name = 'captcha_auth']:checked").val();
	 var button_status = $("input[name = 'button_status']:checked").val();
	 var select_type = $("input[name = 'select_type']:checked").val();
	 var fields = '';
     $('input[name="fields"]:checked').each(function(){ 
		fields += ',' + $(this).val();
     }); 
	 fields = fields.substr(1);
	 
	 var tip = '添加';
	 var ajax = new $ax(Feng.ctxPath + "/Sys.Action/add", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(tip + "成功" );
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(tip + "失败！" + data.msg + "！");
		 }
	 }, function (data) {
	 	Feng.error("操作失败!" + data.responseJSON.message + "!");
	 });
	 ajax.set('is_controller_create',is_controller_create);
	 ajax.set('is_service_create',is_service_create);
	 ajax.set('is_view_create',is_view_create);
	 ajax.set('is_view',is_view);
	 ajax.set('log_status',log_status);
	 ajax.set('api_auth',api_auth);
	 ajax.set('sms_auth',sms_auth);
	 ajax.set('captcha_auth',captcha_auth);
	 ajax.set('button_status',button_status);
	 ajax.set('select_type',select_type);
	 ajax.set('fields',fields);
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};


CodeInfoDlg.update = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }

	 var is_controller_create = $("input[name = 'is_controller_create']:checked").val();
	 var is_service_create = $("input[name = 'is_service_create']:checked").val();
	 var is_view_create = $("input[name = 'is_view_create']:checked").val();
	 var is_view = $("input[name = 'is_view']:checked").val();
	 var log_status = $("input[name = 'log_status']:checked").val();
	 var api_auth = $("input[name = 'api_auth']:checked").val();
	 var sms_auth = $("input[name = 'sms_auth']:checked").val();
	 var captcha_auth = $("input[name = 'captcha_auth']:checked").val();
	 var button_status = $("input[name = 'button_status']:checked").val();
	 var select_type = $("input[name = 'select_type']:checked").val();
	 var fields = '';
     $('input[name="fields"]:checked').each(function(){ 
		fields += ',' + $(this).val();
     }); 
	 fields = fields.substr(1);
	 var tip = '修改';
	 var ajax = new $ax(Feng.ctxPath + "/Sys.Action/update", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(tip + "成功" );
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(tip + "失败！" + data.msg + "！");
		 }
	 }, function (data) {
	 	Feng.error("操作失败!" + data.responseJSON.message + "!");
	 });

	 ajax.set('is_controller_create',is_controller_create);
	 ajax.set('is_service_create',is_service_create);
	 ajax.set('is_view_create',is_view_create);
	 ajax.set('is_view',is_view);
	 ajax.set('log_status',log_status);
	 ajax.set('api_auth',api_auth);
	 ajax.set('sms_auth',sms_auth);
	 ajax.set('captcha_auth',captcha_auth);
	 ajax.set('button_status',button_status);
	 ajax.set('select_type',select_type);
	 ajax.set('fields',fields);
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};

CodeInfoDlg.fast = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }

	 var actions = '';
     $('input[name="action"]:checked').each(function(){ 
		actions += ',' + $(this).val();
     }); 
	 actions = actions.substr(1);
	 
	 var tip = '添加';
	 var ajax = new $ax(Feng.ctxPath + "/Sys.Action/fast", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(tip + "成功" );
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(tip + "失败！" + data.msg + "！");
		 }
	 }, function (data) {
	 	Feng.error("操作失败!" + data.responseJSON.message + "!");
	 });
	 ajax.set('actions',actions);
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};




CodeInfoDlg.validate = function () {
	  $('#CodeInfoForm').data("bootstrapValidator").resetForm();
	  $('#CodeInfoForm').bootstrapValidator('validate');
	  return $("#CodeInfoForm").data('bootstrapValidator').isValid();
};


$(function () {
	   Feng.initValidator("CodeInfoForm", CodeInfoDlg.validateFields);
});


</script>

{/block}
